package arithmetic.LeetCode;

import groovy.json.JsonOutput;

/**
 * @author jiangfeng 2019/7/26 15:11
 */
public class RemoveDupicatesFromSortArray {

    public static void main(String[] args) {
        int[] a={1,1,2};
        int[] a2 ={0,0,1,1,1,2,2,3,3,4};
        System.out.println( removeDuplicates(a2));
        System.out.println(JsonOutput.toJson(a2));
    }


    public static int removeDuplicates(int[] nums) {
        int newIndex=0;
        for(int i=1;i<nums.length;i++){
            if(nums[i]!=nums[newIndex]){
                nums[++newIndex]=nums[i];
            }
        }
        return newIndex;
    }

}
